<?php

namespace Trawind\Remotes\Repositories\Inventory\Locations;

use Illuminate\Http\Request;
use Trawind\Remotes\BaseRepository;
use Trawind\Remotes\Contracts\Repositories\Inventory\Locations\LocationRepository;
use Trawind\Basics\Enums\ServiceDomain;

/**
 * Class LocationsRemoteEloquent.
 *
 * @package namespace Trawind\Remotes\Repositories\Inventory\Locations;
 */
class LocationsRepositoryEloquent extends BaseRepository implements LocationRepository
{

    public $baseRoute='/locations/locations';

    /**
     * LocationsRemoteEloquent constructor.
     * @param  Request  $request
     */
    public function __construct(Request $request)
    {
         $this->domain = ServiceDomain::INVENTORY_DOMAIN();
    }

    public function create(array $attributes)
    {
        return $this->setUrl($this->baseRoute)
            ->setClientOptions(['form_params' => $attributes])
            ->result('POST');
    }

    /**
     * @param string[] $columns
     * @return mixed|null
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function all($columns = ['*'])
    {
        return $this->setUrl($this->baseRoute)->result();
    }

    public function find($id, $columns = ['*'])
    {
        return $this->setUrl($this->baseRoute.'/'.$id)->result();
    }

    /**
     * @param $limit
     * @return mixed|null
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getLocationsList($limit)
    {
        $this->params['pageSize'] = $limit;
        return $this->setUrl($this->baseRoute)->setClientOptions(['query' => $this->params])->result();
    }

    public function update(array $attributes, $id)
    {
        return $this->setUrl($this->baseRoute.'/'.$id)
            ->setClientOptions(['form_params' => $attributes])
            ->result('PUT');
    }
}
